/**
 * 活动相关API
 * 对接Java后端: /api/mobile/event
 */

const { get, post } = require('../utils/request');

/**
 * 获取活动列表
 * GET /api/mobile/event/list
 */
function getEventList(params = {}) {
  return get('/mobile/event/list', params);
}

/**
 * 获取活动详情
 * GET /api/mobile/event/:id
 */
function getEventDetail(id) {
  return get(`/mobile/event/${id}`);
}

/**
 * 创建活动
 * POST /api/mobile/event/create
 */
function createEvent(eventData) {
  return post('/mobile/event/create', eventData);
}

/**
 * 报名参加活动
 * POST /api/mobile/event/:id/signup?note=xxx
 * 注：note作为query参数传递
 */
function signupEvent(eventId, note = '') {
  const url = `/mobile/event/${eventId}/signup${note ? `?note=${encodeURIComponent(note)}` : ''}`;
  return post(url);
}

/**
 * 取消报名
 * POST /api/mobile/event/:id/cancel
 */
function cancelSignup(eventId) {
  return post(`/mobile/event/${eventId}/cancel`);
}

/**
 * 活动签到
 * POST /api/mobile/event/:id/checkin
 */
function checkIn(eventId) {
  return post(`/mobile/event/${eventId}/checkin`);
}

/**
 * 活动评价
 * POST /api/mobile/event/:id/rate?rating=5&review=xxx
 * 注：rating和review作为query参数传递
 */
function rateEvent(eventId, rating, review = '') {
  const url = `/mobile/event/${eventId}/rate?rating=${rating}${review ? `&review=${encodeURIComponent(review)}` : ''}`;
  return post(url);
}

/**
 * 获取我的报名记录
 * GET /api/mobile/event/my-signups
 */
function getMySignups(status = '') {
  return get('/mobile/event/my-signups', status ? { status } : {});
}

/**
 * 检查是否已报名
 * GET /api/mobile/event/:id/has-signed-up
 */
function hasSignedUp(eventId) {
  return get(`/mobile/event/${eventId}/has-signed-up`);
}

module.exports = {
  getEventList,
  getEventDetail,
  createEvent,
  signupEvent,
  cancelSignup,
  checkIn,
  rateEvent,
  getMySignups,
  hasSignedUp
};
